package com.da.im.common;

import com.alibaba.fastjson2.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author da
 * @time 2023/12/20 上午 9:45
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WsResult {
    private String name;
    private String msg;
    private LocalDateTime time;

    public static TextWebSocketFrame error(String msg) {
        return new TextWebSocketFrame(JSON.toJSONString(new WsResult("系统消息", msg, LocalDateTime.now())));
    }

    public static TextWebSocketFrame success(String msg) {
        return new TextWebSocketFrame(JSON.toJSONString(new WsResult("系统消息", msg, LocalDateTime.now())));
    }

    public static TextWebSocketFrame success(String name, String msg) {
        return new TextWebSocketFrame(JSON.toJSONString(new WsResult(name, msg, LocalDateTime.now())));
    }

}
